<!doctype html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{baseui/head :: head}">
    <link rel="stylesheet" href="/adminthemes/layuii/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/adminthemes/bootstrop/bootstrap/dist/css/bootstrap.css" media="all">
    <meta charset="UTF-8">
    <meta name=”viewport” content=”width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes” />
    <title>添加供应商</title>
</head>

<body>
<br>
<h1 style="font-size: 20px;margin-left: 40%;font-weight: bold">添加供应商</h1>
<form class="form-horizontal group-border-dashed" action="#"
      style="border-radius: 0px;">
    <div class="form-group">
        <label class="col-sm-3 control-label" >供应商名称</label>
        <div class="col-sm-6">
            <input type="text" class="form-control" placeholder="请输入供应商名称"
                   id="suppliername"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >供应商登录时所需密码</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入供应商登录时所需密码" id="supplierpassword"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >供应商手机号</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入供应商手机号" id="suppliermobile"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >供应商联系人</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入供应商联系人" id="supplieruser"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >供应商联系电话</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入供应商联系电话" id="suppliertel"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >供应商身份证号</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入供应商身份证号" id="suppliercard"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >供应商联系地址</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入供应商联系地址" id="supplieraddress"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >经营范围</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入供应商经营范围" id="bussiness_scope"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="status">是否启用</label>
        <div class="col-sm-6" style="width: 150px">
            <select class="form-control" name="devicetype" id="status">
                <option value="1">是</option>
                <option value="0">否</option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >供应商详细说明</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入供应商详细说明" id="supplierdetail"/>
        </div>
    </div>
    <div style="text-align: center" class="layui-upload">
        <div class="layui-upload-list">
            <img class="layui-upload-img" style="width:100px;height:100px;" id="pic1">
            <p id="demoText"></p>
            <!--<img class="layui-upload-img" src="" style="width:100px;height:100px;display: none" id="pic">-->
            <input id="pic" name="pic" type="hidden"/>
        </div>
        <button type="button" class="btn btn-primary" id="test1">
            上传logo图片
        </button>
    </div>
    <div class="form-actions">
        <button style="margin-left:40%" type="button" class="btn btn-primary"
                onclick="saveInsurance()">
            保存
        </button>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <button class="btn" type="reset" onclick="repic()">重写</button>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <button style="margin-left:5%" class="btn" type="button" onclick="history.back()">返回
        </button>

    </div>
</form>

</div>

<script type="text/javascript" src="/adminthemes/bootstrap/bootstrap.switch/bootstrap-switch.min.js"></script>
<script src="/adminthemes/bootstrap/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="//cdn.bootcss.com/bootstrap-treeview/1.1.0/bootstrap-treeview.min.js"></script>
<script type="text/javascript" src="/adminthemes/layuii/layui/layui.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    function  saveInsurance() {
        layui.use('layer', function () {
        var $ = layui.jquery, layer = layui.layer;
        var suppliername=$("#suppliername").val();
        var suppliermobile=$("#suppliermobile").val();
        var supplierpassword=$("#supplierpassword").val();
        var supplierdetail=$("#supplierdetail").val();
        var status=$("#status").val();
        var pic=$("#pic").val();
        var supplieruser=$("#supplieruser").val();
        var suppliertel=$("#suppliertel").val();
        var suppliercard=$("#suppliercard").val();
        var supplieraddress=$("#supplieraddress").val();
        var bussiness_scope=$("#bussiness_scope").val();
        if (suppliername==""){
            layer.alert('请输入供应商名称！');
            return false;
        }
        if (supplierdetail==""){
            layer.alert('请输入供应商详细信息！');
            return false;
        }
        if (supplierpassword==""){
            layer.alert('请输入供应商登录时密码！');
            return false;
        }
        if (suppliermobile.length<11){
            layer.alert('请输入十一位手机号！');
            return false;
        }
        if (supplieruser==""){
            layer.alert('请输入供应商联系人！');
            return false;
        }
        if (suppliertel==""){
            layer.alert('请输入供应商电话！');
            return false;
        }
        if (suppliercard==""||suppliercard.length!=18){
            layer.alert('请输入正确的供应商身份证号！');
            return false;
        }
        if (supplieraddress==""){
            layer.alert('请输入十一位手机号！');
            return false;
        }
        if (bussiness_scope==""){
            layer.alert('请输入供应商经营范围！');
            return false;
        }
        var postData = {
            suppliername:suppliername,
            suppliermobile:suppliermobile,
            supplierpassword:supplierpassword,
            supplierdetail:supplierdetail,
            status:status,
            supplieruser:supplieruser,
            suppliertel:suppliertel,
            suppliercard:suppliercard,
            supplieraddress:supplieraddress,
            bussiness_scope:bussiness_scope,
            pic:pic,
        }
        $.ajax({
            type: "POST",
            url: "/web/supplier/add.do",
            data: postData,
            dataType: "json",
            success: function (data) {
                if (data = true) {
                    layer.open({
                        content: '添加完成，请返回'
                        , yes: function (index, layero) {
                            location.href = '/shop/admin/goods/list.do';
                        }
                        , cancel: function () {
                            return false;// 开启该代码可禁止点击该按钮关闭
                        }
                    });
                }
                else {
                    layer.alert('添加失败，请重试！');
                }
            }
        })
        });
    }
    layui.use('upload', function(){
        var $ = layui.jquery
            ,upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '/admin/insurancecom/upload/companylogo1.do'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#pic1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
//                layer.alert(res);
//                alert(res);
//                console.info(res);
                if(res.success){
//                    $('#pic').attr('src', res.result);
                   $("#pic").val(res.result);
                    return   layer.alert('上传成功！');;
                }
            }
        })
    });

</script>

</body>
</html>